/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.romerito.gui.splash;

import br.com.romerito.app.MidletApp;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author Romerito Campos
 */
public class SplashScreen extends Canvas implements Runnable{

    private Image logo;

    public SplashScreen() {
        setFullScreenMode(true);

        try {            
            logo = Image.createImage("/back2.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        Thread thread = new Thread(this);
        thread.start();
    }

    protected void paint(Graphics g) {
        g.setColor(0x00ffffff);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.drawImage(logo, getXPosition()+1, getYPosition(), Graphics.TOP|Graphics.LEFT);

    }

    private int getXPosition(){
        if(getWidth()==128)
            return 0;
        else{
            int x = getWidth()-128;
            return x/2;
        }
    }

    private int getYPosition(){
        if(getHeight()==160){
            return 0;
        }else{
            int x = getHeight()-160;
            return x/3;
        }
    }

    public void run(){
        try {

            Thread.sleep(4000);

        } catch (InterruptedException ex) {
            
            ex.printStackTrace();
            
        }
        MidletApp.app.showMenu();
    }

}
